(function($, doc){    
    var originalDocTitle = doc.title,
        scrollingPtr = null,
        frequence = 500,
        titleScroller = function (title) {
            doc.title = title;
            scrollingPtr = (function(){
                titleScroller(title.substr(1) + title.substr(0, 1));
            }).defer(frequence);
        };
     
    ujs.define('titleScroller', 'ujs.browser', {
        /**
         * 滚动显示指定的标题. 
         */
        scroll : function(title){
            if(scrollingPtr){
                window.clearTimeout(scrollingPtr);
            }
            titleScroller(title);    
        },
        /**
         * 恢复原始页面标题. 
         */
        restore : function(){
            if(scrollingPtr){
                window.clearTimeout(scrollingPtr);
            }
            doc.title = originalDocTitle;
        } 
    });
})($, document);